local chungao = fk.CreateSkill {
  name = "th_chungao",
  tags = { Skill.Switch }
}

chungao:addEffect(fk.EventPhaseProceeding, {
  anim_type = "switch",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(chungao.name) and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local state = player:getSwitchSkillState(chungao.name)
    local all_players = room:getAlivePlayers(false)
    local n = math.max(math.ceil(#all_players / 2), 1)
    local players = Util.DummyTable
    if state == fk.SwitchYang then
      players = table.filter(all_players, function(p) return p:getHandcardNum() <= p.maxHp end)
    elseif state == fk.SwitchYin then
      players = table.filter(all_players, function(p) return p:getHandcardNum() >= p.hp end)
    end
    local targets = room:askToChoosePlayers(player, {
      targets = players,
      min_num = 1,
      max_num = n,
      prompt = Fk:translate("#th_chungao-ask")..Fk:translate("#th_chungao-"..state)..":::"..n,
      skill_name = chungao.name,
      cancelable = true
    })
    if #targets ~= 0 then
      event:setCostData(self, { tos = targets, state = state })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat = event:getCostData(self)
    local state = dat.state
    local tos = dat.tos
    room:sortByAction(tos)
    for _, to in ipairs(tos) do
      if state == fk.SwitchYang then
        to:drawCards(2)
      elseif state == fk.SwitchYin then
        room:loseHp(to, 1, chungao.name)
      end
    end
  end,
})

Fk:loadTranslationTable{
  ["th_chungao"] = "春告",
  [":th_chungao"] = "转换技，准备阶段，你可以令至多X名（X为存活角色数的一半，向上取整）：<br>" ..
  "阳：手牌数不大于其体力上限的角色摸两张牌；<br>" ..
  "阴：手牌数不小于其体力值的角色失去1点体力。",

  [":th_chungao_yang"] = "转换技，准备阶段，你可以令至多X名（X为存活角色数的一半，向上取整）：<br>" ..
  "<font color=\"#E0DB2F\">阳：手牌数不大于其体力上限的角色摸两张牌；</font><br/>" ..
  "阴：手牌数不小于其体力值的角色失去1点体力。",
  [":th_chungao_yin"] = "转换技，准备阶段，你可以令至多X名（X为存活角色数的一半，向上取整）：<br>" ..
  "阳：手牌数不大于其体力上限的角色摸两张牌；<br>" ..
  "<font color=\"#E0DB2F\">阴：手牌数不小于其体力值的角色失去1点体力。</font>",

  ["#th_chungao-ask"] = "春告：你可以选择至多%arg名角色，令其",
  ["#th_chungao-0"] = "摸两张牌",
  ["#th_chungao-1"] = "失去1点体力",
}

return chungao